package com.zslc.securitymonitoring.service.impl;

import com.zslc.securitymonitoring.dao.VulMapper;
import com.zslc.securitymonitoring.entity.VulDict;
import com.zslc.securitymonitoring.enums.AlermTypeEnum;
import com.zslc.securitymonitoring.enums.VulTypeEnum;
import com.zslc.securitymonitoring.service.VulService;
import com.zslc.securitymonitoring.util.ResultCMS;
import com.zslc.securitymonitoring.util.StringUtils;
import com.zslc.securitymonitoring.vo.GlobalSeverityVO;
import com.zslc.securitymonitoring.vo.VulStatisticVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

/**
 * @version 1.0
 * @description:
 * @author: Gaoyc
 * @date: 2024-06-12 16:37
 **/
@Service
public class VulServiceImpl implements VulService {
    @Resource
    private VulMapper vulMapper;
    @Override
    public List<VulStatisticVO> vulStatisticBy6Month() {
        List<VulStatisticVO> list = vulMapper.vulStatisticBy6Month();

        List<VulDict> dictList = vulMapper.selectVulDict();
        list.forEach(l -> {
            VulDict vulDict = dictList.parallelStream().filter(v -> StringUtils.equalsAnyIgnoreCase(v.getXml(), l.getVulSlug())).findAny().orElse(null);
            if(Optional.ofNullable(vulDict).isPresent()) {
                l.setVulSlugName(vulDict.getName());
            }
        });
        return list;
    }
}
